#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;
using uint = unsigned int;
using pii = pair<uint, uint>;
using piii = pair<uint, pii>;

int n, m;
uint a[N];
int rt[N];
struct Node {
  int cnt;
  int ch[2];
} tr[N * 40];
#define cnt(p) tr[p].cnt
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
int newnode(int p) {
  static int tot = 0;
  ++tot;
  cnt(tot) = cnt(p);
  lc(tot) = lc(p);
  rc(tot) = rc(p);
  return tot;
}
void insert(int &rt, uint x) {
  rt = newnode(rt);
  cnt(rt)++;
  int p = rt;
  per(i, 31, 0) {
    if (x & (1u << i))
      rc(p) = newnode(rc(p)), p = rc(p);
    else
      lc(p) = newnode(lc(p)), p = lc(p);
    cnt(p)++;
  }
}
void del(int &rt, uint x) {
  rt = newnode(rt);
  cnt(rt)--;
  int p = rt;
  per(i, 31, 0) {
    if (x & (1u << i))
      rc(p) = newnode(rc(p)), p = rc(p);
    else
      lc(p) = newnode(lc(p)), p = lc(p);
    cnt(p)--;
  }
}
uint query(int &rt, uint x) {
  uint res = 0;
  int p = rt;
  per(i, 31, 0) {
    int c = (x & (1u << i)) ? 1 : 0;
    if (!cnt(tr[p].ch[c])) c ^= 1;
    p = tr[p].ch[c];
    if (c) res |= 1u << i;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) a[i] ^= a[i - 1];
  insert(rt[0], 0);
  rep(i, 1, n) {
    rt[i] = rt[i - 1];
    insert(rt[i], a[i]);
  }
  priority_queue<piii> pq;
  rep(i, 1, n) {
    uint x = query(rt[i], ~a[i]);
    pq.push(piii(a[i] ^ x, pii(i, x)));
  }
  ll sum = 0;
  while (pq.size() && m--) {
    piii now = pq.top();
    pq.pop();
    sum += now.first;
    int i = now.second.first;
    uint x = now.second.second;
    del(rt[i], x);
    x = query(rt[i], ~a[i]);
    if (a[i] ^ x) pq.push(piii(a[i] ^ x, pii(i, x)));
  }
  cout << sum;
  return 0;
}